<?php
class AES
{
    protected $method;
    protected $secret_key;
    protected $iv;
    protected $options; 
    public function __construct($key, $method = 'AES-128-ECB', $iv = '', $options = OPENSSL_RAW_DATA)
    {
        $this->secret_key = $key;
        $this->method = $method;
        $this->iv = $iv;
        $this->options = $options;
    }
    function encrypt($data)
    {
        return bin2hex(openssl_encrypt($data, $this->method, $this->secret_key, $this->options, $this->iv));
    }
    function decrypt($data)
    {
        return openssl_decrypt(hex2bin($data), $this->method, $this->secret_key, $this->options, $this->iv);
    }
}